package pl.ptemich.bumbastic.physics;


/**
 * @author Elmo
 *
 */
public class Circle extends AbstractCollisionShape  {
  
  
  private int radius;

  
  @Override
  public boolean checkColision(CollisionShape obj) {
    if (obj instanceof Circle) {
      return checkColision((Circle) obj);
    } else if (obj instanceof Rectangle) {
      return checkColision((Rectangle) obj);
    }
    
    return false;
  }
  
  public boolean checkColision(Rectangle obj) {
    if ((position.getPosX() + getRadius() > (obj.position.getPosX() - obj.getWidth()/2)) //from the left 
        && (position.getPosX() - getRadius() < (obj.position.getPosX() + obj.getWidth()/2)) //from the right
        && (position.getPosY() + getRadius() > (obj.position.getPosY() - obj.getHeight()/2)) //from the bottom
        && (position.getPosY() - getRadius() < (obj.position.getPosY() + obj.getHeight()/2))) //from the top
    {
      return true;
    }
    
    return false;
  }
  
  public boolean checkColision(Circle obj) {
    if ((obj.getRadius() + radius) > Math.sqrt(((obj.position.getPosX() - position.getPosX()) * (obj.position.getPosX() - position.getPosX())) + ((obj.position.getPosY() - position.getPosY()) * (obj.position.getPosY() - position.getPosY())))) {
      return true;
    }
      
    return false;
  }  
  

  public int getRadius() {
    return radius;
  }
}
